from flask import Blueprint, request
from ..controllers.user import register, login, get_user, get_all_users, update_user, delete_user

auth_bp = Blueprint("auth", __name__, url_prefix="/auth")
user_bp = Blueprint("users", __name__, url_prefix="/users")


# 认证路由
@auth_bp.route("/register", methods=["POST"])
def route_register():
    data = request.get_json() or {}
    return register(data)

@auth_bp.route("/login", methods=["POST"])
def route_login():
    data = request.get_json() or {}
    return login(data)

# 用户管理路由
@user_bp.route("/list", methods=["GET"])
def route_get_all_users():
    data = request.args.to_dict() or {}
    return get_all_users(data)

# 用户详情路由
@user_bp.route("/user", methods=["GET"])
def route_get_user():
    data = request.args.to_dict() or {}
    return get_user(data)

# 用户编辑路由
@user_bp.route("/edit", methods=["POST"])
def route_update_user():
    data = request.get_json() or {}
    return update_user(data)    

# 用户删除路由
@user_bp.route("/delete", methods=["POST"])
def route_delete_user():
    data = request.get_json() or {}
    return delete_user(data)
